export default () => {
  const image = new Map<mapkey, HTMLImageElement>()

  //   加载图片
  const loadImages = async (obj: Record<string, string>) => {
    const promises: Promise<HTMLImageElement>[] = []
    Object.entries(obj).map(([key, value]) => {
      promises.push(
        new Promise((resolve) => {
          const img = document.createElement('img')
          img.src = value
          img.onload = () => {
            image.set(key as mapkey, img)
            resolve(img)
          }
        }),
      )
    })
    await Promise.all(promises)
  }

  return { image, loadImages }
}
